<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

	<#-- 已经登录，不再显示login页面，跳转到home页面 -->
	<#if user??>
	<meta http-equiv="refresh" content="0; url=../shortcut/home" />
	</#if>

    <title>${system.name}</title>

    <!-- Bootstrap core CSS -->

    <link href="../../fonts/css/font-awesome.min.css" rel="stylesheet">
    <link href="../../css/animate.min.css" rel="stylesheet">

    <!-- Custom styling plus plugins -->
    <link href="../../css/custom.css" rel="stylesheet">
    <link href="../../css/icheck/flat/green.css" rel="stylesheet">
    <link href="../../css/bootstrap.min.css" rel="stylesheet">


    <script src="../../js/jquery.min.js"></script>

    <!--[if lt IE 9]>
        <script src="../assets/js/ie8-responsive-file-warning.js"></script>
        <![endif]-->

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
          <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
        <![endif]-->
<script type="text/javascript">

if(location.href.substring(0,location.href.indexOf(".")) == "http://tjdxjyxy"){
    location.replace("/scheduling/html/login/yghq/");
}else if(location.href.substring(0,location.href.indexOf(".")) == "http://yghq"){
    location.replace("http://yghq.cdu-mt.com/scheduling/anon/webportal/firstpage/");
}else if(location.href.substring(0,location.href.indexOf(".")) == "http://yghqpub"){
    location.replace("http://yghqpub.cdu-mt.com/scheduling/html/login/yghq/");
}else{
    // location.replace("/bdzh/");
    location.replace("/scheduling/html/login/yghq/");
}

var code ; //在全局 定义验证码  
function createCode()  
{  
    code = "";  
    var codeLength = 4;//验证码的长度  
    //所有候选组成验证码的字符，可以用中文  
    /* var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');  */
    var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'); 
    for(var i=0;i<codeLength;i++)  
    {  
        var charIndex = Math.floor(Math.random()*selectChar.length);  
        code +=selectChar[charIndex];  
    }
    return code;  
}  
function validate()  
{  
  	
     var inputCode = document.getElementById("vcode").value.toLowerCase();  
    if(inputCode.length <=0)  
    {  
        $("#message").html("请输入验证码！");
        return false;  
    }  
    else if(inputCode != code.toLowerCase())  
    {  
        $("#message").html("验证码输入错误！");
        document.getElementById("vcode").value="";
        show();//刷新验证码  
        return false;  
    }  
    else  
    {  
        trylogin();
		
        return true;  
    }  
}  
function show(){  
        //显示验证码  
        document.getElementById("code").src="/scheduling/LoginCode.jsp?code="+createCode();
}  
window.onload = function() {//document.onload=show();  
        show();//页面加载时加载验证码  
        //这时无论在ie还是在firefox中，js没有加载完，页面的东西是不会被执行的；  
}  

function trylogin(){

    var params = {
           username : $('input[name="username"]').val(),
           password : $('input[name="password"]').val(),
           site_id  : $('select[name="site_id"]').val()
    }
    
    var logparams = {
           logusername : $('input[name="username"]').val(),
           password : $('input[name="password"]').val(),
           site_id  : $('select[name="site_id"]').val()
    }
    
    $.ajaxSettings.async = false;
    var retFlg =false;
    // 是否10分钟输入错误六次
    $.ajax({    
        url: '/scheduling/api/login/getLoginErrorTimes',
        data: logparams,
        type:'POST',
        success: function(data){
                if(data.data[0][0].failcnt >= 6
                    || ( data.data[0][0].failcnt == 0
                        && data.data[1][0].failcnt >= 6)){
                    alert("账户已锁定，请10分钟后再试！");
                    retFlg = true;
                }
        },
        error: function(data){
                alert("登录失败，请稍后再试！");
                retFlg = true;
        }
    });
    $.ajaxSettings.async = true;
    if (retFlg){
        return;
    }
   
    $.ajax({    
        url: '/scheduling/tryLogin',
        data: params,
        type:'POST',
        success: function(data){
                var enforceLoginFlg =false;
                if(data>0){
                    enforceLoginFlg = confirm("同一账户已登录，切断此用户连接，并强制登录？");
                }else{
                    enforceLoginFlg = true;
                }
                if(enforceLoginFlg){
                    $("#loginform").submit();
                }
        },
        error: function(data){
                alert("登录失败，请稍后再试！");
        }
    });
}

$(function(){
	$("#reset_btn").click(function(){
		$("#txtuid").val("");
		$("#txtpwd").val("");
	});
});

$(function(){
   $(".close").click(function(){
      $("#myAlert").addClass("hide");
   });
});
function getKey()  
{  
    if(event.keyCode==13){  
     	validate();  
     	
    }     
}

</script>
</head>

<body style="background:url('/scheduling/html/pub/bg.jpg') no-repeat 100% 100%;background-size:100% 100%;height:100%;" onkeypress="getKey();">
    
    <div class="">
        <a class="hiddenanchor" id="toregister"></a>
        <a class="hiddenanchor" id="tologin"></a>

        <div id="wrapper">
            <div id="login" class="animate form">
                <section class="login_content">
                    <form action="" method="POST" accept-charset="UTF-8" id="loginform" style='background:#ffffff;padding:20px;box-shadow: 0 0  50px  #123a77;'>
                        <h1>${system.name}</h1>
                    <#--
                        <div style="padding-bottom: 20px;">
                        	<#if request.getParameter("site_id")??>
                        	<#assign site_id = request.getParameter("site_id")>
                       		<input type="hidden" name="site_id" value="${site_id}">
								<#list data[0] as item><#if item.site_id = site_id>
								<span class="form-control">${item.name}</span>
								</#if></#list>
                        	<#else>
	                        <select name="site_id" class="form-control" tabindex="1">
								<#list data[0] as item>
								<option value="${item.site_id}">${item.name}</option>
								</#list>
							</select>
							</#if>
                        </div>
                    -->
                        <div>
                            <input type="text" name="username" class="form-control" placeholder="输入用户名" required="" tabindex="2" />
                        </div>
                        <div>
                            <input type="password" name="password" class="form-control" placeholder="输入密码" required="" tabindex="3" />
                        </div>
                        <div>
                        <input name="txtpic" type="text" maxlength="4" id="vcode" style="width:150px;display:inline-block;margin-left:-50px" class="form-control" placeholder="输入验证码" required=""  tabindex="4" />
                            <img src="" class="but_blue" style="width:80px; margin-top:-10px" id="code" align="middle" />
	          				<a href="#"  style="color:#000;line-height:30px;" onclick="javascript:show();return false;">看不清？</a>
                        </div>
                        <div class="clearfix">
                            <input type="button" class="btn btn-default pull-left" onclick="validate();" value="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;登&nbsp;&nbsp;录&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" tabindex="5"/>
                            <a class="pull-right" href="#">忘了密码?</a>
                        </div>
                        <br/>
                        <div id="myAlert"  style="display:inline-back;background-color:#faebcc;"><span id="message" style="color:#F00;font-size:18px;">${(request.getAttribute("shiroLoginFailure")??)?then('用户名或密码错误！','')}</span></div>
                        	
                        <div class="separator">
                            <div>
                                <p>版权所有 © 2017 睦通科技政企服务云</p>
                            </div>
                        </div>
                    </form>
                    <!-- form -->
                </section>
                <!-- content -->
            </div>
            <div id="register" class="animate form">
                <section class="login_content">
                    <form>
                        <h1>Create Account</h1>
                        <div>
                            <input type="text" class="form-control" placeholder="Username" required="" />
                        </div>
                        <div>
                            <input type="email" class="form-control" placeholder="Email" required="" />
                        </div>
                        <div>
                            <input type="password" class="form-control" placeholder="Password" required="" />
                        </div>
                        <div>
                            <a class="btn btn-default submit" href="index.html">Submit</a>
                        </div>
                        <div class="clearfix"></div>
                        <div class="separator">

                            <p class="change_link">Already a member ?
                                <a href="#tologin" class="to_register"> Log in </a>
                            </p>
                            <div class="clearfix"></div>
                            <br />
                            <div>
                                <h1><i class="fa fa-paw" style="font-size: 26px;"></i> ${system.name}</h1>

                                <p>版权所有 © 2017 睦通科技政企服务云</p>
                            </div>
                        </div>
                    </form>
                    <!-- form -->
                </section>
                <!-- content -->
            </div>
        </div>
    </div>

</body>

</html>